<template>
    <div>
        <h2>房号添加</h2>
        <table class="table table-bordered">
            <tbody>

                <tr>
                    <td>房号</td>
                    <td>

                        <input type="text" v-model="obj.Number">
                    </td>
                </tr>




                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="obj.HouseTypeId">
                            <option value="-1">请选择</option>
                            <option v-for="item in data.list" :key="item.Id" :value="item.Id">{{ item.HouseTypeName }}
                            </option>
                        </select>
                    </td>
                </tr>



                <tr>
                    <td>备注</td>
                    <td>

                        <textarea cols="30" rows="10" v-model="obj.BeiZhu"></textarea>
                    </td>
                </tr>



                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="isAddBed" value="1" v-model="obj.State" />上架
                        <input type="radio" name="isAddBed" value="0" v-model="obj.State" />下架
                    </td>
                </tr>




                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-success" @click="ok" />
                    </td>
                </tr>



            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()


let obj = reactive({
    "Number": '',
    "HouseTypeId": -1,
    "BeiZhu": '',
    "State": 1
})




//添加
const ok = () => {
    axios({
        url: 'https://localhost:7059/api/HouseType/HouseNoAdd',
        method: 'post',
        data: obj
    }).then((res) => {
        console.log(res)
        if (res.data > 0) {
            alert('添加成功')
            router.push('/HouseNoList')
            return;
        }
        else {
            alert('添加失败')
            return;
        }
    })
        .catch((err) => {
            console.log(err)
        })
}



let model = reactive({
    HouseTypeName: '',
    index: 1,
    size: 10,

})

let data: any = reactive({
    list: [],
    count: 0,
    page: 0,

})


//房型列表
onMounted(() => {
    getlist();
})



//显示
const getlist = () => {


    axios({
        url: 'https://localhost:7059/api/HouseType/HouseTypeList',
        method: 'get',
        params: model,

    })
        .then((res) => {
            console.log(res);
            data.list = res.data.list;
            data.count = res.data.count;
            data.page = res.data.page;
        })
        .catch((err) => {
            console.log(err);
        })

}

</script>

<style scoped></style>